package sevensoft.gz031.demos.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sevensoft.gz031.demos.web.entity.CarbonEmission;
import sevensoft.gz031.demos.web.response.R;
import sevensoft.gz031.demos.web.service.CarbonEmissionService;

/**
 * 双碳配置—固定碳排放
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/carbonEmission")
public class CarbonEmissionController {

    @Autowired
    CarbonEmissionService carbonEmissionService;

    /**
     * 新增
     * @param carbonEmission
     * @return
     */
    @PutMapping
    public R<?> add(@RequestBody CarbonEmission carbonEmission){
        return R.ok(carbonEmissionService.add(carbonEmission));
    }

    /**
     * 修改
     * @param carbonEmission
     * @return
     */
    @PostMapping
    public R<?> update(@RequestBody CarbonEmission carbonEmission){
        return R.ok(carbonEmissionService.update(carbonEmission));
    }

    /**
     * 删除
     * @param carbonEmission
     * @return
     */
    @DeleteMapping
    public R<?> remove(@RequestBody CarbonEmission carbonEmission){
        return R.ok(carbonEmissionService.remove(carbonEmission));
    }

    /**
     * 分页查询
     * @param page
     * @param count
     * @return
     */
    @GetMapping("/{page}/{count}")
    public R<IPage<CarbonEmission>> selectByPage(@PathVariable("page")Integer page,@PathVariable("count")Integer count){
        return R.ok(carbonEmissionService.selectByPage(page,count));
    }

    /**
     * 模糊查询
     * @param page
     * @param count
     * @param energyConsumptionItem
     * @param projectType
     * @param timeType
     * @return
     */
    @GetMapping("/fuzzy/{page}/{count}/{energyConsumptionItem}/{projectType}/{timeType}")
    public R<IPage<CarbonEmission>> selectByFuzzy(
            @PathVariable("page")Integer page,
            @PathVariable("count")Integer count,
            @PathVariable("energyConsumptionItem")String energyConsumptionItem,
            @PathVariable("projectType")String projectType,
            @PathVariable("timeType")String timeType
    ){
        CarbonEmission carbonEmission1 = new CarbonEmission();
        return R.ok(carbonEmissionService.selectByFuzzy(page,count,carbonEmission1));
    }
}
